using System;
using System.Reflection;

namespace UFrame
{
    public static class AssemblyTool
    {

        private static Assembly cacheAssembly;

        public static string cacheAssemblyName = "Assembly-CSharp";

        public static Type SearchType(string className)
        {
            Type tType = null;
            if (cacheAssembly != null)
            {
                tType = cacheAssembly.GetType(className);
            }

            if (tType == null)
            {
                tType = Type.GetType(className);
            }

            if (tType == null)
            {
                Array array = AppDomain.CurrentDomain.GetAssemblies();
                foreach (var item in array)
                {
                    Assembly a = item as Assembly;
                    tType = a.GetType(className);

                    if (cacheAssemblyName == a.GetName().Name)
                    {
                        cacheAssembly = a;
                    }

                    if (tType != null)
                    {
                        break;
                    }
                }
            }

            return tType;
        }
    }
}